# coding: utf-8 
"""
@Time    : 2024/8/16 15:24
@Author  : Y.H LEE
"""
from sys_params import *

import numpy as np
import torch.nn
from tqdm import tqdm

from utils.tools import *


class MyEvaluator:

    def __init__(self):
        super(MyEvaluator, self).__init__()

    def evaluate(self, model, dataloader):
        mse_loss_list = []
        mape_loss_list = []
        sgcc_list = []
        with torch.no_grad():
            model.eval()
            # pbar = tqdm(range(eval_batch_len), desc=mode, total=eval_batch_len)
            # for step in pbar:
            for step, data in enumerate(dataloader):
                mse_loss, mape_loss, sgcc = model(data)

                mse_loss_list.append(mse_loss.cpu().item())
                mape_loss_list.append(mape_loss.cpu().item())
                sgcc_list.append(sgcc.cpu().item())

        return (torch.mean(torch.tensor(np.array(mse_loss_list), dtype=torch.float, device=device)),
                torch.mean(torch.tensor(np.array(mape_loss_list), dtype=torch.float, device=device)),
                torch.mean(torch.tensor(np.array(sgcc_list), dtype=torch.float, device=device)))


if __name__ == '__main__':
    pass
